/*
 * BallCarlos.java
 *
 * Created on 29 de Junho de 2007, 13:35
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package characters;

import Utils.Coordenate;
import java.util.Random;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author JAKE
 */
public class BallCarlos extends Sprite {
    
    
    int DISP_WIDTH;
    int DISP_HEIGHT;
    
    /**
     * The width of the ball's bounding rectangle.
     */
    static int WIDTH = 40;
    
    /**
     * The height of the ball's bounding rectangle.
     */
    private static int HEIGHT = 40;
    
    static int[] FRAME_SEQUENCE={1};
    
    /**
     * the X coordinate of the cowboy where the cowboy starts
     * the game.
     */
    int X;
    
    /**
     * the Y coordinate of the cowboy when not jumping.
     */
    int Y;
    
    private boolean goingUp = false;
    
    private boolean goingRight= false;
    
    
    /** Creates a new instance of BallCarlos */
    public BallCarlos(int initialX, int initialY, int DISP_WIDTH, int DISP_HEIGHT) throws Exception{
        super(Image.createImage("/characters/images/BallCarlos.png"), WIDTH, HEIGHT);
        
        X = initialX;
        Y = initialY;
        this.DISP_WIDTH = DISP_WIDTH;
        this.DISP_HEIGHT = DISP_HEIGHT;
        // we define the reference pixel to be in the middle
        // of the cowboy image so that when the cowboy turns
        // from right to left (and vice versa) he does not
        // appear to move to a different location.
        defineReferencePixel(WIDTH/2, 0);
        setRefPixelPosition(X, Y);
        //setFrameSequence(FRAME_SEQUENCE);
    }
    
    private void keepOnBoundaries(){
        
        if(X >= DISP_WIDTH){
            setGoingRight(true);
        }
        if(X <= 0){
            setGoingRight(false);
        }
        if(Y >= DISP_HEIGHT){
            setGoingUp(false);
        }
        if(Y <= 0){
            setGoingUp(true);
        }
        
    }
    
    public void execute(){
        
        keepOnBoundaries();
        
        if(isGoingRight())
            X--;
        else
            X++;
        if(isGoingUp())
            Y++;
        else
            Y--;
        
        setRefPixelPosition(X, Y);
        
    }
    
    public static int getHEIGHT() {
        return HEIGHT;
    }
    
    public static void setHEIGHT(int aHEIGHT) {
        HEIGHT = aHEIGHT;
    }
    
    public void setGoingUp(boolean control){
        goingUp = control;
    }

    public boolean isGoingUp() {
        return goingUp;
    }

    public boolean isGoingRight() {
        return goingRight;
    }

    public void setGoingRight(boolean goingRight) {
        this.goingRight = goingRight;
    }
    
}
